

#import "AwesomeMenuViewController.h"
#import "AwesomeMenu.h"
#import "AwesomeMenuItem.h"
#import "FlyLevel.h"
#import "AbstractLevelFactory.h"
#import "AbstractLevel.h"
#import "LevelLists.h"

@interface AwesomeMenuViewController ()
@property UIWindow* window;
@property SKView* skView;
@property NSArray* levelList;
@end

@implementation AwesomeMenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    LevelLists* list = [[LevelLists alloc] init];
    self.levelList = list.levelList;
    
    self.view.backgroundColor = [UIColor darkGrayColor];

    //self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"train"]];
    
    UIScreen* mainscreen = [UIScreen mainScreen];
    UIImageView* backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"train"]];
    [backgroundImageView sizeThatFits:mainscreen.bounds.size];
    [self.view addSubview:backgroundImageView];
    
    UIImage *storyMenuItemImage = [UIImage imageNamed:@"bg-menuitem.png"];
    UIImage *storyMenuItemImagePressed = [UIImage imageNamed:@"bg-menuitem-highlighted.png"];
    
    UIImage *starImage = [UIImage imageNamed:@"icon-star.png"];
    UIImage* scubaDiceImage = [UIImage imageNamed:@"Water_sports_and_recreation_tours_Scuba_Diving-64.png"];
    UIImage* shuriken = [UIImage imageNamed:@"shuriken.png"];
    UIImage* cards = [UIImage imageNamed:@"cards32.png"];
    UIImage* ninja = [UIImage imageNamed:@"ninja64.png"];
    UIImage* balance = [UIImage imageNamed:@"bmicon.png"];
    UIImage* bottles = [UIImage imageNamed:@"bottleIcon1.png"];
    UIImage* type = [UIImage imageNamed:@"handIcon1.png"];
    
    // Default Menu
    
    //PoppingCirclesLevelItem
    AwesomeMenuItem *starMenuItem1 = [[AwesomeMenuItem alloc] initWithImage:scubaDiceImage
                                                           highlightedImage:storyMenuItemImagePressed
                                                               ContentImage:scubaDiceImage
                                                    highlightedContentImage:nil];
    
    AwesomeMenuItem *starMenuItem2 = [[AwesomeMenuItem alloc] initWithImage:shuriken
                                                           highlightedImage:storyMenuItemImagePressed
                                                               ContentImage:shuriken
                                                    highlightedContentImage:nil];
    AwesomeMenuItem *starMenuItem3 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
                                                           highlightedImage:storyMenuItemImagePressed
                                                               ContentImage:ninja
                                                    highlightedContentImage:nil];
    AwesomeMenuItem *starMenuItem4 = [[AwesomeMenuItem alloc] initWithImage:type
                                                           highlightedImage:storyMenuItemImagePressed
                                                               ContentImage:type
                                                    highlightedContentImage:nil];
    AwesomeMenuItem *starMenuItem5 = [[AwesomeMenuItem alloc] initWithImage:balance
                                                           highlightedImage:storyMenuItemImagePressed
                                                               ContentImage:balance
                                                    highlightedContentImage:nil];
    AwesomeMenuItem *starMenuItem6 = [[AwesomeMenuItem alloc] initWithImage:bottles
                                                           highlightedImage:storyMenuItemImagePressed
                                                               ContentImage:bottles
                                                    highlightedContentImage:nil];
    AwesomeMenuItem *starMenuItem7 = [[AwesomeMenuItem alloc] initWithImage:cards
                                                           highlightedImage:storyMenuItemImagePressed
                                                               ContentImage:cards
                                                    highlightedContentImage:nil];
//    AwesomeMenuItem *starMenuItem8 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
//                                                           highlightedImage:storyMenuItemImagePressed
//                                                               ContentImage:starImage
//                                                    highlightedContentImage:nil];
//    AwesomeMenuItem *starMenuItem9 = [[AwesomeMenuItem alloc] initWithImage:storyMenuItemImage
//                                                           highlightedImage:storyMenuItemImagePressed
//                                                               ContentImage:starImage
//                                                    highlightedContentImage:nil];
    
    NSArray *menus = [NSArray arrayWithObjects:starMenuItem1, starMenuItem2, starMenuItem3, starMenuItem4, starMenuItem5, starMenuItem6, starMenuItem7, nil];
    
    AwesomeMenuItem *startItem = [[AwesomeMenuItem alloc] initWithImage:[UIImage imageNamed:@"bg-addbutton.png"]
                                                       highlightedImage:[UIImage imageNamed:@"bg-addbutton-highlighted.png"]
                                                           ContentImage:[UIImage imageNamed:@"icon-plus.png"]
                                                highlightedContentImage:[UIImage imageNamed:@"icon-plus-highlighted.png"]];
    
    
    
    AwesomeMenu* menu =[[AwesomeMenu alloc] initWithFrame:self.view.bounds startItem:startItem optionMenus:menus];
    
    menu.startPoint= CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2);
    menu.farRadius = 230.0f;
    menu.nearRadius = 180.0f;
    menu.endRadius=230;
    
    menu.delegate = self;
    
    
    
    [self.view addSubview:menu];
    // [self.window makeKeyAndVisible];
}

- (BOOL)shouldAutorotate
{
    return YES;
}


- (NSUInteger)supportedInterfaceOrientations
{
    
    return UIInterfaceOrientationMaskLandscapeLeft;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)awesomeMenu:(AwesomeMenu *)menu didSelectIndex:(NSInteger)idx
{
    NSString* levelName = [self.levelList objectAtIndex:idx];
    NSLog(@"IDX is - %d ..... and the array is : - %@" , idx , self.levelList);
    
    AbstractLevel* scene = [AbstractLevelFactory sceneFactory:levelName];
    scene.scaleMode = SKSceneScaleModeResizeFill;
    self.skView = [[SKView alloc] initWithFrame:self.view.bounds];
    NSLog(@"THE ABSTRACT LEVEL IS  - %@ ..... THE SKVIEW IS  - %@ ",scene , self.skView);
    [self.view addSubview:self.skView];
    self.skView.showsFPS=YES;
    [self.skView presentScene:scene];
    
    
}
- (void)awesomeMenuDidFinishAnimationClose:(AwesomeMenu *)menu {
    NSLog(@"Menu was closed!");
}
- (void)awesomeMenuDidFinishAnimationOpen:(AwesomeMenu *)menu {
    NSLog(@"Menu is open!");
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
